﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class InvoicePaymentHistories : _InvoicePaymentHistories
    {
        public static InvoicePaymentHistories AddPaymentHistory(int invoiceID, int paymentMethodID, Decimal paidAmt, DateTime paidDate,
            int saleUser)
        {
            InvoicePaymentHistories hist = new InvoicePaymentHistories();
            hist.AddNew();
            hist.BranchID = Branches.CurrentBranchID;
            hist.InvoiceID = invoiceID;
            hist.PaymentMethodID = paymentMethodID;
            hist.PaidAmount = paidAmt;
            hist.PaidDate = paidDate;
            hist.SaleUser = saleUser;
            hist.LastModifiedByUser = saleUser;
            hist.LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            hist.Deleted = false;
            
            hist.Save();

            return hist;
        }

        public void AddPayment(int invoiceID, int paymentMethodID, Decimal paidAmt, DateTime paidDate,
            int saleUser)
        {
            AddNew();
            BranchID = Branches.CurrentBranchID;
            InvoiceID = invoiceID;
            PaymentMethodID = paymentMethodID;
            PaidAmount = paidAmt;
            PaidDate = paidDate;
            SaleUser = saleUser;
            LastModifiedByUser = saleUser;
            LastModifiedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            Deleted = false;
        }

        public static InvoicePaymentHistories LoadPaymentByInvoiceID(int invoiceID)
        {
            InvoicePaymentHistories p = new InvoicePaymentHistories();
            p.Where.InvoiceID.Value = invoiceID;
            p.Query.Load();
            return p;
        }
    }
}
